import Vue from "vue";
import Router from "vue-router";
import store from "../store/index";

Vue.use(Router);

const router = new Router({
  routes: [
    {
      path: "/",
      redirect: "/index"
    },
    {
      path: "/index",
      component: () => import("@/views/index/index"),
      meta: {
        title: "天慈医院",
        // 缓存首页
        keepAlive: true
      }
    },{
      path: "/needRed",
      component: () => import("@/views/index/needRed/index"),
      meta: {
        title: "挂号须知内容"
      }
    },{
      path: "/visitorCard",
      component: () => import("@/views/index/visitorCard/index"),
      meta: {
        title: "家庭成员",
		needLogin:true
      }
    },{
      path: "/addVisitor",
      component: () => import("@/views/index/addVisitor/index"),
      meta: {
        title: "新增就诊人"
      }
    },{
      path: "/visitorShow",
      component: () => import("@/views/index/visitorShow/index"),
      meta: {
        title: "就诊人详情"
      }
    },{
      path: "/doctorShow",
	  name:'doctorShow',
      component: () => import("@/views/index/doctorShow/index"),
      meta: {
        title: "医生主页"
      }
    },{
      path: "/choose",
      component: () => import("@/views/index/choose/index"),
      meta: {
        title: "选择科室",
		needLogin:true,
		keepAlive: true
      }
    },{
      path: "/register",
      component: () => import("@/views/index/register/index"),
      meta: {
        title: "",
		keepAlive: true
      }
    },{
      path: "/chooseTime",
	  name:'chooseTime',
      component: () => import("@/views/index/chooseTime/index"),
      meta: {
        title: "分时段号源"
      }
    },{
      path: "/registerShow",
      component: () => import("@/views/index/register/registerShow"),
      meta: {
        title: "挂号详情"
      }
    },
	{
	  path: "/myRegistration",
	  component: () => import("@/views/index/myRegistration/index"),
	  meta: {
	    title: "我的挂号",
		needLogin:true
	  }
	},{
	  path: "/report",
	  component: () => import("@/views/index/report/index"),
	  meta: {
	    title: "报告查询",
		needLogin:true
	  }
	},{
	  path: "/checkReportShow",
	  component: () => import("@/views/index/report/checkReportShow"),
	  meta: {
	    title: "检查报告"
	  }
	},{
	  path: "/testReportShow",
	  component: () => import("@/views/index/report/testReportShow"),
	  meta: {
	    title: "检验报告"
	  }
	},
	{
	  path: "/pay",
	  component: () => import("@/views/index/pay/index"),
	  meta: {
	    title: "门诊缴费",
		needLogin:true
	  }
	},{
	  path: "/payshow",
	  component: () => import("@/views/index/pay/show"),
	  meta: {
	    title: "门诊缴费"
	  }
	},
	{
	  path: "/yibaoPay",
	  component: () => import("@/views/index/pay/yibaoPay"),
	  meta: {
	    title: "确认支付"
	  }
	},{
	  path: "/intro",
	  component: () => import("@/views/index/pay/intro"),
	  meta: {
	    title: "操作流程"
	  }
	},{
	  path: "/deptList",
	  component: () => import("@/views/index/content/deptList"),
	  meta: {
	    title: "科室导航"
	  }
	},{
	  path: "/deptShow",
	  component: () => import("@/views/index/content/deptShow"),
	  meta: {
	    title: ""
	  }
	},{
	  path: "/show",
	  component: () => import("@/views/index/content/show"),
	  meta: {
	    title: "山西天慈医院简介"
	  }
	},{
	  path: "/brainShow",
	  component: () => import("@/views/index/content/brainShow"),
	  meta: {
	    title: "脑卒中筛查"
	  }
	},{
	  path: "/medicalCenter",
	  component: () => import("@/views/index/content/medicalCenter"),
	  meta: {
	    title: "体检中心",
		
	  }
	},{
	  path: "/healthCheckup",
	  component: () => import("@/views/index/healthCheckup/report"),
	  meta: {
	    title: "体检报告查询",
		needLogin:true
	  }
	},{
	  path: "/accompanying",
	  component: () => import("@/views/index/content/accompanying"),
	  meta: {
	    title: "陪护服务"
	  }
	},{
	  path: "/accompanyingDiagnosis",
	  component: () => import("@/views/index/content/accompanyingDiagnosis"),
	  meta: {
	    title: "陪诊服务"
	  }
	},
    {
      path: "/login",
      component: () => import("@/views/login/index"),
      meta: {
        title: "登录"
      }
    },
    {
      path: "*",
      component: () => import("@/components/NotFound")
    }
  ]
});

router.beforeEach((to, from, next) => {
  let { title, needLogin } = to.meta;
  let { isLogin } = store.state;
  document.title = title;

  if (needLogin && !isLogin) {
    next({
      path: "/login"
    });
  } else {
    next();
  }
});

export default router;
